//
//  MSCustomView.swift
//  weibo
//
//  Created by JLHong on 15/12/15.
//  Copyright © 2015年 long. All rights reserved.
//

import UIKit

class MSCustomView: UIView {
   
    //MARK:-- 分局子空间 --
    override init(frame: CGRect) {
       super.init(frame: frame)
        
        showSubViews()
        self.backgroundColor = UIColor(white: 237 / 255.0, alpha: 1)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

 func setupVistorView(imageName: String, message: String) {

        iconView.image = UIImage(named: imageName)
        centerLabel.text = message
        centerLabel.sizeToFit()
        homeView.hidden = true
        coverView.hidden = true
    }

    
  private  func showSubViews(){
        
        addSubview(iconView)
        addSubview(coverView)
        addSubview(homeView)
        addSubview(centerLabel)
        addSubview(resignBitton)
        addSubview(loginButton)
    
        iconView.translatesAutoresizingMaskIntoConstraints = false
        homeView.translatesAutoresizingMaskIntoConstraints = false
        centerLabel.translatesAutoresizingMaskIntoConstraints = false
        resignBitton.translatesAutoresizingMaskIntoConstraints = false
        loginButton.translatesAutoresizingMaskIntoConstraints = false
        coverView.translatesAutoresizingMaskIntoConstraints = false
    
        self.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
    
        self.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: -40))
    
        self.addConstraint(NSLayoutConstraint(item: homeView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
    
        self.addConstraint( NSLayoutConstraint(item: homeView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
    
        self.addConstraint(NSLayoutConstraint(item: centerLabel, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
    
        self.addConstraint(NSLayoutConstraint(item: centerLabel, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
    
        self.addConstraint(NSLayoutConstraint(item: resignBitton, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100))
    
        self.addConstraint(NSLayoutConstraint(item: resignBitton, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 35))
    
        self.addConstraint(NSLayoutConstraint(item: resignBitton, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: centerLabel, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
    
        self.addConstraint(NSLayoutConstraint(item: resignBitton, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: centerLabel, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0))
    
        self.addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100))
    
        self.addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 35))
    
        self.addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: centerLabel, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
    
        self.addConstraint(NSLayoutConstraint(item: loginButton, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: centerLabel, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
    
    // 遮罩约束
 
    addConstraint(NSLayoutConstraint(item: coverView, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0))

    addConstraint(NSLayoutConstraint(item: coverView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
  
    addConstraint(NSLayoutConstraint(item: coverView, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
  
    addConstraint(NSLayoutConstraint(item: coverView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: loginButton, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
    )}
    
    //MARK:-- 懒加载控件 --
   private lazy var iconView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
   private lazy var homeView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
   private lazy var coverView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    
   private lazy var centerLabel: UILabel = {
        let label = UILabel()
        
        label.font = UIFont.systemFontOfSize(15)
        label.text = "关注一些人,看看这里有什么惊喜"
        label.textColor = UIColor.darkGrayColor()
        
        return label
    }()
    
   private lazy var resignBitton: UIButton = {
       let button = UIButton()
        
        button.setTitle("注册", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        return button
    }()
    
   private lazy var loginButton: UIButton = {
       let button = UIButton()
        
        button.setTitle("登陆", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        return button
    }()
 
}
